﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BCGC.BLL.Helper;
using System.Collections.Specialized;
using BCGC.BLL.BusinessObject.UserAccount;
using Jalal.Library.Utility;

public partial class Confirmation : PublicBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (ExtendedSessionManager.CurrentRegistrationStep != RegistrationStep.Confirm)
        {
            Response.Redirect(CustomSiteMap.Register);
        }
        LoadData();
    }

    private void LoadData()
    {
        StringDictionary registerInfo = ExtendedSessionManager.RegistrationInformation;
        ExtendedSessionManager.RegistrationInformation = registerInfo;
        lblUsername.Text = Security.BindStringInput(registerInfo["Username"], SecurityLevel.Three);
        lblEmail.Text = Security.BindStringInput(registerInfo["Email"], SecurityLevel.Three);
        lblSecretQuestion.Text = Security.BindStringInput(registerInfo["SecretQuestion"], SecurityLevel.Three);
        lblSecretAnswer.Text = Security.BindStringInput(registerInfo["SecretAnswer"], SecurityLevel.Three);
    }

    protected void GoBack_Click(object sender, EventArgs e)
    {
        ExtendedSessionManager.RegistrationInformation = null;
        ExtendedSessionManager.CurrentRegistrationStep = RegistrationStep.Input;
        Response.Redirect(CustomSiteMap.Home);
    }

    protected void Continue_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            StringDictionary registerInfo = ExtendedSessionManager.RegistrationInformation;

            SiteUser user = new SiteUser();
            string verificationCode = user.Register(Security.BindStringInput(registerInfo["Username"], SecurityLevel.Three),
                Security.BindStringInput(registerInfo["Password"], SecurityLevel.Three),
                Security.BindStringInput(registerInfo["Email"], SecurityLevel.Three),
                Security.BindStringInput(registerInfo["SecretQuestion"], SecurityLevel.Three),
                Security.BindStringInput(registerInfo["SecretAnswer"], SecurityLevel.Three));

            registerInfo.Add("VerificationCode", verificationCode);
            ExtendedSessionManager.CurrentRegistrationStep = RegistrationStep.Complete;
            ExtendedSessionManager.RegistrationInformation = registerInfo;
            Response.Redirect(CustomSiteMap.RegistrationComplete);
        }
    }
}
